package cn.orangeframe.neon.application.tasks;

import cn.orangeframe.neon.application.run.WorkflowExecutor;
import cn.orangeframe.neon.domain.enums.TaskStatus;
import cn.orangeframe.neon.domain.enums.TaskType;
import cn.orangeframe.neon.domain.model.TaskModel;
import cn.orangeframe.neon.domain.model.WorkflowModel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import static cn.orangeframe.neon.domain.enums.TaskStatus.*;

@Slf4j
@Component
public class Terminate extends WorkflowSystemTask {

    private static final String TERMINATION_STATUS_PARAMETER = "terminationStatus";
    private static final String TERMINATION_REASON_PARAMETER = "terminationReason";
    private static final String TERMINATION_WORKFLOW_OUTPUT = "workflowOutput";

    public Terminate() {
        super(TaskType.TASK_TYPE_TERMINATE);
    }

    @Override
    public void execute(WorkflowModel workflow, TaskModel task, WorkflowExecutor executor) {
        log.info("Executing terminate task: {},{}", task.getTaskReferenceName(), task.getTaskId());
        task.setStatus(TaskStatus.COMPLETED);
    }

    public static Boolean validateInputStatus(String status) {
        return COMPLETED.name().equals(status)
                || FAILED.name().equals(status);
    }

    public static String getTerminationStatusParameter() {
        return TERMINATION_STATUS_PARAMETER;
    }

    public static String getTerminationReasonParameter() {
        return TERMINATION_REASON_PARAMETER;
    }

    public String getTerminationWorkflowOutput() {
        return TERMINATION_WORKFLOW_OUTPUT;
    }
}
